#include <iostream>
#include <vector>
using namespace std;
class Solution {
    public:
        int maxArea(vector<int>& height) {

            int len = height.size();
            if (len < 2)
                return 0;
            if (len == 2) {
                return height[0] < height[1] ? height[0] : height[1];
            }

            int max_area = 0;
            int h = 0, w = 0;
            int i = 0;
            int j = len - 1;
            int tmp_area = 0;

            while(i < j) {
                w = j-i;
                h = height[i] > height[j] ? height[j] : height[i];
                tmp_area = w * h;
                if (tmp_area > max_area) {
                    max_area = tmp_area;
                }
                if (height[i] < height[j]) {
                    i ++;
                } else {
                    j --;
                }

            }

            return max_area;
        }

};

int main() {

//    vector<int> v = {1,8,6,2,5,4,8,3,7};
    vector<int> v = {2,3,10,5,7,8,9};
    Solution s;
    cout << s.maxArea(v) << endl;

}
